package com.example.photography.adapter.community;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.example.photography.R;
import com.example.photography.bean.CommunityBean;
import com.example.photography.ui.CircleImageView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class Community_LabelAdapter extends RecyclerView.Adapter<Community_LabelAdapter.ViewHolder> {
    private final Context context;
    private List<CommunityBean.DataBean.LabelBean> labelBeans;

    public Community_LabelAdapter(List<CommunityBean.DataBean.LabelBean> labelBeans, Context context) {
        this.labelBeans = labelBeans;
        this.context = context;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.label_community, parent, false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {

        holder.rabName.setText(labelBeans.get(position).getType());
        List<CommunityBean.DataBean.LabelBean.DatelistBean> datelistBeans = labelBeans.get(position).getDatelist();
//        if (datelistBeans!=null&&datelistBeans.size()>0){
//
//        }

        //glide头像加载实现
        //1
        Glide.with(context)
                .load(datelistBeans.get(0).getHead_url())
                .thumbnail(Glide.with(context).load(R.drawable.head_empty))
                .apply(RequestOptions.bitmapTransform(new RoundedCorners(30)))
                .into(holder.cvHead1);
        holder.tvName1.setText(datelistBeans.get(0).getName());

        //2
        Glide.with(context)
                .load(datelistBeans.get(1).getHead_url())
                .thumbnail(Glide.with(context).load(R.drawable.head_empty))
                .apply(RequestOptions.bitmapTransform(new RoundedCorners(30)))
                .into(holder.cvHead2);
        holder.tvName2.setText(datelistBeans.get(1).getName());

        Glide.with(context)
                .load(datelistBeans.get(2).getHead_url())
                .thumbnail(Glide.with(context).load(R.drawable.head_empty))
                .apply(RequestOptions.bitmapTransform(new RoundedCorners(30)))
                .into(holder.cvHead3);
        holder.tvName3.setText(datelistBeans.get(2).getName());
//        Rab_lvAdapter rab_lvAdapter = new Rab_lvAdapter(labelBeans.get(position).getDatelist(), context);
//        holder.lv.setAdapter(rab_lvAdapter);
    }

    @Override
    public int getItemCount() {
        return labelBeans == null ? 0 : labelBeans.size();
    }


    static
    class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.rab_name)
        TextView rabName;
        @BindView(R.id.cv_head1)
        CircleImageView cvHead1;
        @BindView(R.id.tv_name1)
        TextView tvName1;
        @BindView(R.id.cv_head2)
        CircleImageView cvHead2;
        @BindView(R.id.tv_name2)
        TextView tvName2;
        @BindView(R.id.cv_head3)
        CircleImageView cvHead3;
        @BindView(R.id.tv_name3)
        TextView tvName3;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
